package com.beep.erp.http;


import com.beep.erp.common.base.BaseBean;
import com.beep.erp.common.bean.ResultBean;

import rx.functions.Func1;

/**
 * FileName: HttpResultFunc
 * description:  用来统一处理Http的resultCode,并将HttpResult的Data部分剥离出来返回给subscriber
 * Subscriber真正需要的数据类型，也就是Data部分的数据类型
 * Author: Jolly
 * Date: 2018/08/22
 */
public class HttpResultFunc<T extends BaseBean> implements Func1<ResultBean<T>, T> {
    @Override
    public T call(ResultBean<T> httpResult) {
        if (httpResult.isOk()) {
            throw new HttpExceptionHandle.ServerException(httpResult.getCode(), httpResult.getMessage());
        }
        return httpResult.getMessages();
    }
}
